<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="../../css/mui.min.css" />
		<link rel="stylesheet" type="text/css" href="../../css/pages/user/myhuos.css" />
	</head>

	<body style="background-color: #F7F7F7;">

		<div id="app"> 
			<div class="list"> 
				<div class="list-item" v-for="(item,index) in hous" @click="onHous(index)">
					<div>{{item.neiName}}</div>
					<div>{{item.buiName}}{{item.eleName}}{{item.roomEncode}}</div>
					<img class="item-icon" v-if="num==index" src="../../images/saff-img.png" >
				</div>
			</div>  
			<div class="defaults" @click="onDefaults">设为默认房屋</div>
		</div>

		<script src="../../js/Width.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/mui.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/vue.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/Util.js" type="text/javascript" charset="utf-8"></script>
		<script src="https://cdn.bootcss.com/fastclick/1.0.6/fastclick.min.js"></script>
		<script type="text/javascript">
			mui.init({
				beforeback: function() {
					var neiID = Util.getState('hosing').neiID
					if(!neiID) {
						console.log('不存在')
						app.oNreturn()
						var list = plus.webview.currentWebview().opener();
						//触发列表界面的自定义事件（refresh）,从而进行数据刷新
						mui.fire(list, 'oNreturn');
						//返回true，继续页面关闭逻辑
						return true;
					} 
				}
			})
			mui.plusReady(function() {
				ws = plus.webview.currentWebview();
				ws.setStyle({
					titleNView: {
						titleText: "房屋信息",
						autoBackButton: true,
						backgroundColor: "#fff"
					}
				})
				
				if (mui.os.ios) { //判断是ios还是安卓设备
					FastClick.attach(document.body);
					ws.setStyle({
						'popGesture': 'none'
					}); 
				}
// 				if (mui.os.android) {
// 					//安卓按两次关闭app
// 					var clickNum = 0;
// 					mui.back = function(event) {
// 						clickNum++;
// 						if (clickNum == 2) {
// 							plus.runtime.quit();
// 						} else {
// 							mui.toast("再按一次退出应用");
// 						}
// 						setTimeout(function() {
// 							clickNum = 0;
// 						}, 1500);
// 						return false;
// 					}
// 				}
				getHousing()
				if(Util.getState('hosing')){
					app.num = Util.getState('hosing').index || 0
				} 
				
			})

			var app = new Vue({
				el: '#app',
				data: {
					num: 0,
					hous: []
				}, 
				methods: {
					onHous(index) {
						this.num = index
					},
					onDefaults() {
						var data = this.hous[this.num]
						data.index = this.num
						Util.setState('hosing', data)
						mui.toast('设为默认房屋成功')
						plus.runtime.restart()
					},
					oNreturn () {
						var data = this.hous[this.num]
						data.index = this.num
						Util.setState('hosing', data)
						
					}
				}
			})

			function getHousing() {
				var userID = Util.getState('$state').userID // 获取用户ID 
				mui.post(Util.HTTP + 'api/Users/GetHousing', {
					userID: userID
				}, function(res) {
					if (res.code == 1001) {
						console.log(res.message)
						app.hous = res.data
					} else {
						mui.toast(res.message)
					}
				})
			}
		</script>
	</body>
</html>
